package org.example.contract.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import org.example.contract.domain.ContractPartner;
import org.example.contract.service.IContractPartnerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同合作伙伴Controller
 *
 * @author 小孟微信：xiaomengcode
 * @date 2024-05-25
 */
@Controller
@RequestMapping("/contractPartner/contractPartner")
public class ContractPartnerController extends BaseController
{
    private String prefix = "contractPartner/contractPartner";

    @Autowired
    private IContractPartnerService contractPartnerService;

    @RequiresPermissions("contractPartner:contractPartner:view")
    @GetMapping()
    public String contractPartner(ContractPartner contractPartner ,ModelMap mmp)
    {
        mmp.put("contractPartner",contractPartner);
        return prefix + "/contractPartner";
    }

    /**
     * 查询合同合作伙伴列表
     */
    @RequiresPermissions("contractPartner:contractPartner:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ContractPartner contractPartner)
    {
        startPage();
        List<ContractPartner> list = contractPartnerService.selectContractPartnerList(contractPartner);
        return getDataTable(list);
    }


    /**
     * 新增合同合作伙伴
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存合同合作伙伴
     */
    @RequiresPermissions("contractPartner:contractPartner:add")
    @Log(title = "合同合作伙伴", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ContractPartner contractPartner)
    {
        return toAjax(contractPartnerService.insertContractPartner(contractPartner));
    }


    /**
     * 修改保存合同合作伙伴
     */
    @RequiresPermissions("contractPartner:contractPartner:edit")
    @Log(title = "合同合作伙伴", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ContractPartner contractPartner)
    {
        return toAjax(contractPartnerService.updateContractPartner(contractPartner));
    }

    /**
     * 删除合同合作伙伴
     */
    @RequiresPermissions("contractPartner:contractPartner:remove")
    @Log(title = "合同合作伙伴", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(contractPartnerService.deleteContractPartnerByContractPartnerIds(ids));
    }
}
